package io.github.kimmking.gateway.router.my;

import io.github.kimmking.gateway.router.HttpEndpointRouter;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 轮询
 */
public class MyRoundRibbonHttpEndpointRouter implements HttpEndpointRouter {

    /**
     * 全局轮询索引下标
     */
    private static AtomicInteger currentIndex = new AtomicInteger(0);

    @Override
    public String route(List<String> urls) {
        int index = currentIndex.getAndIncrement();
        return urls.get(index % urls.size());
    }
}
